home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 6317 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.7 KB

  1. Path: ohstpy.mps.ohio-state.edu!vancleef
  2. From: vancleef@ohstpy.mps.ohio-state.edu
  3. Newsgroups: comp.lang.c
  4. Subject: Re: 6 byte real to double; How?
  5. Message-ID: <1996Feb23.160719.8965@ohstpy>
  6. Date: 23 Feb 96 16:07:19 -0500
  7. References: <3128306A.21F@hsc.unt.edu> <4gg88a$3oi@aphex.direct.ca> <312DFBF2.74BB@hsc.unt.edu>
  8. Organization: The Ohio State University, Department of Physics
  9.  
  10. In article <312DFBF2.74BB@hsc.unt.edu>, Steve Fogoros <sfogoros@hsc.unt.edu> writes:
  11. > Ed Toivanen wrote:
  12. >> 
  13. >> In article <3128306A.21F@hsc.unt.edu>, sfogoros@hsc.unt.edu says...
  14. >> >
  15. >> >I have a lot of data files that were created by a pascal program. The
  16. >> >data is stored as 'file of real' meaning that each floating point value
  17. >> >is stored in six bytes. I need to access this data from a c program
  18. >> >(borland). I would like any assistance you could provide. I guess what
  19. >> >I need is a canned function that would take a 6 byte string (actually the
  20. >> >real), and return a double.
  21. >> 
  22. >> You need to know exactly how reals are interpreted by your pascal program. The
  23. >> exact handling of a float is different(X bytes on the left side of the decimal,
  24. >> Y bytes for precision) even across different C compilers, so I don't think
  25. >> pascal would be much different in that respect. Once you know that, the rest is
  26. >> a few C line away.
  27. >> 
  28. >> EdThank you for taking some time to consider my question. I should explain 
  29. > though that I am not referring to the ascii representation of floating 
  30. > point values, but the binary storage format. A six byte real (48 bits) is 
  31. > divided into three fields: one sign bit (s), 39 bits for the significand 
  32. > (f), and 8 bits for the exponent (e). According to Borland specification 
  33. > the value is calculated as:
  34. >    if 0 < e <= 255 then value = (-1)**s * 2**(e-129) * (1.f),
  35. >    if e == 0 then value = 0.
  36.  
  37.  
  38. No. The bias is 127 NOT 129.
  39.  
  40. > A double has one sign bit, 52 bits for the significand (which includes a 
  41. > sign bit), and 11 bits for the exponent.
  42. > The part I'm not sure about is biasing the exponents. The real is biased 
  43. > by 129 and the double is biased by 1023. (I think/hope I've got that 
  44. > right). So, if the real exponent is not zero, I add 894 to it and store 
  45. > the result in the double exponent (11 bits). I would go with this except 
  46. > some numbers convert correctly and some don't. (My testing protocol could 
  47. > be in error as well.)
  48. > I thought you would be interested in a more detailed description of the 
  49. > problem. Also, others may have misunderstood my original question and I 
  50. > hope this clarifies things.
  51. > -- 
  52. > Steve Fogoros, Academic Information Coordinator
  53. > University of North Texas Health Science Center
  54. > 3500 Camp Bowie Boulevard, Fort Worth, Texas 76107-2699
  55. > (817)-735-2162 sfogoros@hsc.unt.edu
  56.